﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp9
{
    class Program
    {
        static Dictionary<int,Student> stu = new Dictionary<int, Student>();
        static void Main(string[] args)
        {
            Student s1 = new Student(1,"张三",25);
            Student s2 = new Student(2,"李四",23);
            stu.Add(s1.ID, s1);
            stu.Add(s2.ID, s2);
            Say();
        }
        public static void Say()
        {
            Console.WriteLine("请选择：1、添加学生信息。2、查询学生信息。");
            int key = int.Parse(Console.ReadLine());

            switch (key)
            {
                case 1:
                    stuAdd();
                    break;
                case 2:
                    Look();
                    break;
                default:
                    break;
            }
        }
        public static void Look()
        {
            Console.WriteLine("1、查询所有（按学号排序）2、查询所有（按姓名排序）3、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
            int key = int.Parse(Console.ReadLine());

            switch (key)
            {
                case 1:
                    List<Student> ID = stu.Values.ToList();
                    ID.Sort(new IDSort());
                    PrintList(ID);
                    Say();
                    break;
                case 2:
                    List<Student> Name = stu.Values.ToList();
                    Name.Sort(new NameSport());
                    PrintList(Name);
                    Say();
                    break;
                case 3:
                    List<Student> Age = stu.Values.ToList();
                    Age.Sort(new AgeSort());
                    PrintList(Age);
                    Say();
                    break;
                case 4:
                    Console.WriteLine("请输入要查询的学号：");
                    int id = int.Parse(Console.ReadLine());
                    if (stu.ContainsKey(id))
                    {
                        Console.WriteLine(stu[id]);
                    }
                    else
                    {
                        Console.WriteLine("查无此学生的信息");
                        Say();
                    }
                    break;
                default:
                    break;
            }
        }
        public static void PrintList(List<Student> list)
        {
            foreach (Student s in list)
            {
                Console.WriteLine(s);
            }
        }
        public static void stuAdd()
        {
            Student s = new Student();

            Console.WriteLine("请输入学号：");
            s.ID = int.Parse(Console.ReadLine());
            if (stu.ContainsKey(s.ID))
            {
                Console.WriteLine("学号重复");
            }
            else
            {
                stu[s.ID] = s;
            }
            Console.WriteLine("请输入姓名：");
            s.Name = Console.ReadLine();
            Console.WriteLine("请输入年龄：");
            s.Name = Console.ReadLine();
            Say();
        }
    }
}
